package com.tul.exercise.base.innerclass.chapter10_8;

/**
 * @Description 《java编程思想》10.8
 *  闭包：
 *
 **/
public class Caller2 extends MyIncrement{
    private int i = 0;

    public void increment() {
        super.increment();
        i++;
        System.out.println(i);
    }

    /**
     *
     * 闭包：持有外部类的引用，实现接口调用
     */
    private class Closure implements  Incrementable{

        @Override
        public void increment() {
            Caller2.this.increment();
        }
    }

    Incrementable getCallbackReference(){
        return new Closure();
    }
}
